﻿using Model.Enum;

namespace Model
{
    /// <summary>
    /// 响应消息
    /// </summary>
    public class ResponseMessage
    {
        /// <summary>
        /// 信息
        /// </summary>
        public string Message { get; set; }
        /// <summary>
        /// 代码
        /// </summary>
        public ResponseType Code { get; set; }
        /// <summary>
        /// 数据
        /// </summary>
        public object? Data { get; set; }
        public ResponseMessage(string message, ResponseType responseType)
        {
            Message = message;
            Code = responseType;
        }
        public ResponseMessage(string message, ResponseType responseType, object? data) : this(message, responseType)
        {
            Data = data;
        }
        /// <summary>
        /// 创建成功响应
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public static ResponseMessage CreateSuccess(string message)
        {
            return new ResponseMessage(message, ResponseType.Success);
        }
        /// <summary>
        /// 创建成功响应
        /// </summary>
        /// <param name="message"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public static ResponseMessage CreateSuccess(string message, object? data)
        {
            return new ResponseMessage(message, ResponseType.Success, data);
        }
        /// <summary>
        /// 创建错误响应
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public static ResponseMessage CreateError(string message)
        {
            return new ResponseMessage(message, ResponseType.Error);
        }
        /// <summary>
        /// 创建被禁止响应
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public static ResponseMessage CreateForbidden(string message)
        {
            return new ResponseMessage(message, ResponseType.Forbidden);
        }
        /// <summary>
        /// 创建未找到响应
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public static ResponseMessage CreateNotFound(string message)
        {
            return new ResponseMessage(message, ResponseType.NotFound);
        }
    }
}
